package demo.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import demo.dao.IShopcartDao;
import demo.model.Shopcart;
import demo.model.vo.ShopcartVO;
import demo.service.IShopcartService;

@RestController
@RequestMapping("shopcart")
public class ShopcartController {

	@Resource
	private IShopcartDao shopcartDao;
	@Resource
	private IShopcartService shopcartService;
	
	
	//��ѯ�û����ﳵ
	@RequestMapping("findCartByUser.do")
	@ResponseBody
	public Map findCartByUser(int uid){
		List<Shopcart> list	= shopcartDao.findCartByUser(uid);
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("status", 0);
		map.put("infoList", list);
		return map;
	}
	
	//��ӵ����ﳵ
	@RequestMapping("addCart.do")
	@ResponseBody
	public int addCart(Shopcart cart) {
		return shopcartService.addCart(cart);
	}
	
	//ɾ�����ﳵ��¼
	@RequestMapping("delCart.do")
	@ResponseBody
	public int delCart(int id) {
		return shopcartDao.delCart(id);
	}
	
	//�޸Ĺ��ﳵ��Ʒ����
	@RequestMapping("addCartNum.do")
	@ResponseBody
	public int addCartNum(int id,int num) {
		return shopcartDao.addCartNum(id, num);
	}
	
	//��ѯ�û����ﳵ��Ʒ����
	@RequestMapping("getCount.do")
	@ResponseBody
	public int getCount(int uid) {
		return shopcartDao.getCount(uid);
	}
	
	@RequestMapping("findCartByUId.do")
	public Map findCartByUId(Integer uid){
		Map map = new HashMap();
		map.put("status", 0);
		map.put("infoList", shopcartDao.findcartByUId(uid));
		return map;
	}
	
	
}
